﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Manson.deviseMode.Single
{
    /// <summary>
    /// 单例对象 
    /// </summary>
    public class SingleObject
    {

        /// <summary>
        /// 私有构造函数，保证该类不能被实例化创建
        /// </summary>
        private  SingleObject()
        {
                
        }

        private static SingleObject singleObject=null;

        private static  Object objLock=new Object();

        /// <summary>
        /// 保证一个类仅有一个实例，并提供一个访问它的全局访问点。
        /// 添加Lock锁避免线程安全调用，
        /// </summary>
        /// <returns></returns>
        public static SingleObject GetInstance()
        {
           if(singleObject==null)
            {
                lock (objLock)
                {
                    if (singleObject == null)
                    {
                        singleObject = new SingleObject();
                    }
                }
            }
           return singleObject;
        }

        public void printerInfo(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}
